/**
 * 项目区域 编辑页
 *
 * 作者 admin
 * 日期 2024-07-29 15:56:11
 */
layui.use(['jquery','febs', 'form', 'validate'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        form = layui.form,
        $view = $('#baseProjectArea-edit'),
        validate = layui.validate;

    form.verify(validate);
    form.render();
    initFormValue();

    function initFormValue() {
        if (baseProjectAreaData) {
            form.val("baseProjectArea-edit-form", {
                "projectAreaId": baseProjectAreaData.projectAreaId,
                "tenantId": baseProjectAreaData.tenantId,
                "areaId": baseProjectAreaData.areaId,
                "areaName": baseProjectAreaData.areaName,
            });
        }
    }

    form.on('submit(baseProjectArea-edit-form-submit)', function (data) {
        addOrUpdate(data.field);
        return false;
    });

    function addOrUpdate(data) {
        if (data.projectAreaId && data.projectAreaId.length > 0) {
            febs.post(ctx + 'baseProjectArea/update', data, function () {
                layer.closeAll();
                febs.alert.success('修改成功');
                febs.reloadPage();
            });
        } else {
            febs.post(ctx + 'baseProjectArea', data, function () {
                layer.closeAll();
                febs.alert.success('新增成功');
                $('#febs-baseProjectArea').find('#query').trigger('click');
            });
        }
    }
});